Analyze passenger car trends
The example below shows how to create statistics on passenger car trends in Norway, including geographical information related to the vehicle owner which is linked to the vehicle dataset via a personal identifier. The variable KJORETOY_FREG_AR
(year of first registration) is used to create trend statistics.
A vehicle dataset is used as the basis (selecting passenger cars), since the focus is on vehicles (and not people). Vehicles with missing links to the municipality are due to the fact that the owner was not resident in Norway at the given time (1/1 2024). These are classified as "Not resident in Norway" in the geographical statistics.
require no.ssb.fdb:32 as db
// Creating passenger cars dataset
create-dataset passenger_cars
import db/KJORETOY_KJT_GRUP 2023-12-31 as vehicle_group
keep if vehicle_group == '101'
drop vehicle_group
import db/KJORETOY_KJ_ART 2023-12-31 as type_of_driving
import db/KJORETOY_FREG_AR 2023-12-31 as model_year
import db/KJORETOY_BRUKTIMP 2023-12-31 as used_import
import db/KJORETOY_DRIVSTOFF_OMK 2023-12-31 as fuel_type
import db/KJORETOY_TEKN_CO2_UTSLIPP 2023-12-31 as emission_co2
import db/KJORETOY_TEKN_DRIVSTOFF_FORBRUK 2023-12-31 as fuel_consumption
import db/KJORETOY_EG_VEKT 2023-12-31 as curb_weight
import db/KJORETOY_KJORETOYID_FNR 2023-12-31 as idnr
piechart type_of_driving
tabulate type_of_driving
piechart used_import
tabulate used_import
destring fuel_type
recode fuel_type (3 4 6 9 10 11 12 13 14 15 = 9)(7 8 = 3 'Hybrid')(5 = 4 'Electric')
piechart fuel_type
tabulate fuel_type, freq cellpct
textblock
Passenger car's age distributed by fuel type (sorted by average age)
endblock
generate age = 2024 - model_year
tabulate fuel_type, summarize(age) rowsort
barchart(mean) age, over(fuel_type)
generate fossil_car = inlist(fuel_type,1,2)
generate hybrid_car = fuel_type == 3
generate electric_car = fuel_type == 4
textblock
Overall sales trend for passenger cars
endblock
barchart(count) model_year
textblock
Fuel trend
endblock
barchart(count) fuel_type if model_year >= 1970, over(model_year) stack
barchart(percent) fuel_type if model_year >= 1970, over(model_year) stack
textblock
Used import trend
endblock
barchart(count) used_import if model_year >= 1970, over(model_year) stack
barchart(percent) used_import if model_year >= 1970, over(model_year) stack
textblock
Emission trend for fossil cars
endblock
summarize emission_co2 if fossil_car
histogram emission_co2 if fossil_car, freq bin(20)
tabulate model_year if fossil_car & model_year >= 2000, summarize(emission_co2) mean freq
generate emission_decile = quantile(emission_co2,10) if fossil_car
barchart(count) emission_decile, over(model_year) stack
barchart(percent) emission_decile, over(model_year) stack
textblock
Consumption trend for fossil cars
endblock
summarize fuel_consumption if fossil_car
tabulate model_year if fossil_car & model_year >= 2000, summarize(fuel_consumption) mean freq
generate consumption_decile = quantile(fuel_consumption,10) if fossil_car
barchart(count) consumption_decile, over(model_year) stack
barchart(percent) consumption_decile if model_year >= 1970, over(model_year) stack
textblock
Curb weight trend
endblock
summarize curb_weight
tabulate fuel_type, summarize(curb_weight)
histogram curb_weight, freq bin(20)
tabulate model_year if model_year >= 2000, summarize(curb_weight) mean freq
generate curb_weight_decile = quantile(curb_weight,10)
barchart(count) curb_weight_decile if model_year >= 2000, over(model_year) stack
barchart(percent) curb_weight_decile if model_year >= 2000, over(model_year) stack
barchart(mean) curb_weight, over(fuel_type)
textblock
Geographical trends
endblock
// Creating population dataset and linking residential information to passenger car dataset
create-dataset population
import db/BEFOLKNING_KOMMNR_FORMELL 2024-01-01 as municipality
merge municipality into passenger_cars on idnr
// Creating geographical statistics for passenger cars
use passenger_cars
generate county = substr(municipality,1,2)
replace county = '99' if sysmiss(county)
define-labels county_labels '03' Oslo '11' Rogaland '15' 'Møre og Romsdal' '18' Nordland '31' Østfold '32' Akershus '33' Buskerud '34' Innlandet '39' Vestfold '40' Telemark '42' Agder '46' Vestland '50' Trøndelag '55' Troms '56' Finnmark '99' 'Not resident in Norway'
assign-labels county county_labels
// Clone municipality variable and extract cities from one variable (the rest are placed in a combined category)
clone-variables municipality -> city
replace city = '9999' if sysmiss(city)
replace city = '8888' if !inlist(city,'0301','1103','3201','3301','4204','4601','5001','5501','9999')
recode city ('8888' = '8888' 'Other municipalities')('9999' = '9999' 'Not resident in Norway')
textblock
Number of passenger cars distributed by owner's place of residence per 1/1 2024
endblock
tabulate county
barchart(count) county
textblock
Number of passenger cars distributed by city (owner's place of residence per 1/1 2024)
endblock
tabulate city
textblock
Fuel type of passenger cars distributed by owner's county of residence
endblock
barchart(count) fuel_type, over(county) stack
barchart(percent) fuel_type, over(county) stack
textblock
Sales trend distributed by counties (owner's place of residence per 1/1 2024)
endblock
barchart(count) county if model_year >= 2000, over(model_year) stack
barchart(percent) county if model_year >= 2000, over(model_year) stack
textblock
Fuel type of passenger cars distributed by cities
endblock
barchart(percent) fuel_type, over(city) stack